// pages/wo/allOrders/allOrders.js
import request from '../../../utils/http.js'
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperHeight:0,
    currentTab: 0, //0:全部 1待付款  2：待发货  3：待收货  4：已完成
    tabList: ["全部","待付款 ","待发货 ", "待收货","已收货","售后中"],
    // tabIndex: 0, //0:全部 1待付款  2：待发货  3：待收货  4：已完成
    IsLogin:false,
    phone:'',
    personId:0,
    shopId:0,
    quanBuList:[],
    daiFaHuoList :[],
    daiShouHuoList :[],
    yiShouHuoList:[],
    shouHouZhongList:[],
    daiFuKuanLength:0,
    daiFaHuoLength:0,
    daiShouHuoLength:0,
    shouHouZhongLength:0,
    hiddenmodalput:true,//物流显示框
    wuLiuGongSi:'',
    wuLiuDanHao:'',
    orderFormId:0,//选择的订单id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      currentTab:options.index,
    })
    // this.changeline();

    var that = this
      wx.getSystemInfo({
        success: function (res) {
          that.setData({
            swiperHeight:res.windowHeight - 44
          });
        }
      });
  },

    /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      IsLogin:wx.getStorageSync(app.globalData.LOGINSTATUS)&&(wx.getStorageSync(app.globalData.PHONENUMBER)!=''),
      phone:wx.getStorageSync(app.globalData.PHONENUMBER),
      personId:wx.getStorageSync(app.globalData.PERSON_ID),
      shopId:wx.getStorageSync(app.globalData.SHOPID),
    })
    this.getOrderList();
  },

  //产品分组切换
  onTabsChange(e){
    let index = e.detail.current==undefined?e.detail.value:e.detail.current
    
    if (this.data.currentTab == index) {
      return false;
    } else {
      this.setData({
        currentTab: index
      })
    }
  },



  //获取订单信息
  getOrderList:function(){
    var that = this
    wx.showLoading({
      title: '加载中...',
      mask: true
    })

    let data = {
      dianPuId:that.data.shopId,
    }

    request.get('OrderForm20231109/chaKanDingDan', data, res => {
     
      // console.log("我的订单:" + JSON.stringify(res.data))

      wx.hideLoading();

      that.setData({
        quanBuList:res.data.quanBuList,
        daiFuKuanList:res.data.daiFuKuanList,
        daiFaHuoList:res.data.daiFaHuoList,
        daiShouHuoList:res.data.daiShouHuoList,
        shouHouZhongList:res.data.shouHouZhongList,
        yiShouHuoList:res.data.yiShouHuoList,
        daiFuKuanLength:res.data.daiFuKuanList.length,
        daiFaHuoLength:res.data.daiFaHuoList.length,
        daiShouHuoLength:res.data.daiShouHuoList.length,
        shouHouZhongLength:res.data.shouHouZhongList.length,
      })
    
    }, err => {
      wx.showToast({
        title: '处理失败，请联系技术人员', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
      wx.hideLoading();
    })


  },


  //订单详情
  toOrderInfo:function(e){
    var id = e.currentTarget.dataset.id;
    var v= e.currentTarget.dataset.v;
    //console.log("id:" + id)
    wx.navigateTo({
      url: '/pkg_wo/pages/orderInfo/orderInfo?orderFormId='+id+'&pathSign=1'+'&orderV='+v,
    })
  },


    //查看物流
    getWuLiuInfo:function(e){
      wx.navigateTo({
        url: '/pkg_wo/pages/wuLiu/wuLiu?orderFormId='+e.currentTarget.dataset.id +  '&orderV='+e.currentTarget.dataset.v,
      })
    },


   //确认收货
    bindQueRenTap:function(e){
      var v= e.currentTarget.dataset.v;

      var url=v==2?'OrderForm20231109/queRenShouHuo':'dingDan/queRenShouHuo'

      console.log("url:"+url)

      var that = this 
      that.setData({
        orderFormId:e.currentTarget.dataset.id,
      })
      var orderFormId=e.currentTarget.dataset.id
     // console.log('orderFormId:'+orderFormId)
    wx.showModal({
                
      title: '确认收货',
      content: '是否确认已收到货？',
      showCancel: true,//是否显示取消按钮
      cancelText:"否",//默认是“取消”
      cancelColor:'#696868',//取消文字的颜色
      confirmText:"是",//默认是“确定”
      confirmColor: '#f92b3a',//确定文字的颜色
      success: function (res) {
         if (res.cancel) {
            //点击取消,默认隐藏弹框
         } else {
   
          let data = {
            orderFormId: orderFormId,
          }
      
          request.get(url, data, res => {
            console.log("修改结果:" + JSON.stringify(res.data))
            wx.hideLoading();  
            if(res.data.status==1){
              that.getOrderList();
              that.setData({
                tabIndex: 3,
              })
            }else{
              wx.showToast({
                title: "确认失败，请联系技术人员！", // 提示的内容
                icon: "none", // 图标，默认success
                duration: 3000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
              })
            }


         
          }, err => {
            wx.showToast({
              title: '处理失败，请联系技术人员', // 提示的内容
              icon: "none", // 图标，默认success
              duration: 1000, // 提示的延迟时间，默认1500
              mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
            wx.hideLoading();
          })



         }
      },
      fail: function (res) { },//接口调用失败的回调函数
      complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
   })


   },

    //申请退款
    toTuiKuanInfo:function(e){
      // console.log(e.currentTarget.dataset.pric)
      wx.navigateTo({
        url: '/pkg_wo/pages/tuiKuan/tuiKuan?orderFormId='+e.currentTarget.dataset.id+'&type='+e.currentTarget.dataset.index+'&pric='+e.currentTarget.dataset.pric + '&orderV='+e.currentTarget.dataset.v,
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },



  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})